import {onBeforeUnmount, onMounted} from 'vue'
import keymaster from 'keymaster'
import {ElMessage} from 'element-plus'

export function keyBind(key: string, message: string, run: Function) {
    onMounted(() => {
        keymaster(key, function () {
            run()
            if (message) {
                ElMessage(message)
            }
            return false
        })
    })

    onBeforeUnmount(() => {
        keymaster.unbind(key)
    })
}
